﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    class DelegateDemo1 {
        public static void Demo() {
            //Test1();
            Test2();
        }

        // 委托是class
        public static void Test2() {
            Type type = typeof(Action);
            Console.WriteLine(type.IsClass);
        }

        public static void Test1() {
            Calculator3 calculator = new Calculator3();
            Action action = new Action(calculator.Report);
            calculator.Report();
            action.Invoke();
            action();

            //
            Func<int, int, int> func1 = new Func<int, int, int>(calculator.Add);
            Func<int, int, int> func2 = new Func<int, int, int>(calculator.Sub);

            int x = 100;
            int y = 200;
            int z = 0;

            z = func1.Invoke(x, y);
            Console.WriteLine(z);
            z = func1(x, y);
            Console.WriteLine(z);
            z = func2.Invoke(x, y);
            Console.WriteLine(z);
            z = func2(x, y);
            Console.WriteLine(z);
        }
    }

    class Calculator3 {
        public void Report() {
            Console.WriteLine("I have 3 methods!");
        }

        public int Add(int a, int b) {
            int result = a + b;
            return result;
        }

        public int Sub(int a, int b) {
            int result = a - b;
            return result;
        }
    }
}
